package com.hgw.Demo05_PrototypePattern.example_ShallowCloning;

/**
 * Data time:2021/12/12 17:13
 * StudentID:2019112118
 * Author:hgw
 * Description: 工作周报类，充当具体原型角色
 */
public class WeeklyLog implements Cloneable{

    // 为了简化设计和实现，假设一份工作周报中只有一个附件对象，在实际情况中可以包含多个附件，可以通过List等集合来实现
    private Attachment attachment;
    private String name;
    private String date;
    private String content;

    public Attachment getAttachment() {
        return attachment;
    }

    public void setAttachment(Attachment attachment) {
        this.attachment = attachment;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    // 使用clone()方法实现浅克隆
    @Override
    protected Object clone() throws CloneNotSupportedException {
        Object obj = null;
        try {
            obj = super.clone();
            return (WeeklyLog)obj;
        } catch (CloneNotSupportedException e) {
            System.out.println("不支持复制！");
            return null;
        }
    }
}
